<template>
	<view class="content">
		<view class="form">
			<view class="titel">
				报工信息
			</view>
			<view class="itembox">
				<view class="name">
					工单待完成数量:
				</view>
				<view class="inputBox">
					<input type="number" v-model="info.remainCount" disabled="" placeholder="请填写工单待完成数量" />
				</view>
			</view>
			<view class="itembox">
				<view class="name">
					报工数量:
				</view>
				<view class="inputBox">
					<input type="number" v-model="count" @input="onKeyInput" placeholder="请填写报工数量" />
				</view>
			</view>
			<view class="itembox" v-if="info.type == 1">
				<view class="name">
					报工小时:
				</view>
				<view class="inputBox">
					<input type="number" v-model="info.hour" @input="onKeysInput" placeholder="请填写报工小时" />
				</view>
			</view>
			<view class="itembox" v-if="info.type == 1">
				<view class="name">
					小时单价:
				</view>
				<view class="inputBox">
					<input type="number" v-model="info.money" disabled="" placeholder="请填写单价" />
				</view>
			</view>
			<view class="itembox" v-if="info.type == 0">
				<view class="name">
					单价:
				</view>
				<view class="inputBox">
					<input type="number" v-model="info.money" disabled="" placeholder="请填写单价" />
				</view>
			</view>
			<view class="itembox">
				<view class="name">
					总价:
				</view>
				<view class="inputBox">
					<input type="number" v-model="info.allMoney" disabled="" placeholder="请填写总价" />
				</view>
			</view>
			<view class="itembox">
				<view class="name">
					备注:
				</view>
				<view class="inputBox">
					<input type="text" v-model="info.remark" placeholder="请输入备注" />
				</view>
			</view>
		</view>
		<view class="bottom-box">
			<view class="bnt" @click="addBnt()">
				报工
			</view>
		</view>
	</view>
</template>

<script>
	// import config from '@/config'
	// import {
	// 	goodsSaledoGongxuUserMoneyInfo,
	// 	addBaogong
	// } from "@/api/system/index"
	// const baseUrl = config.baseUrl
	import * as index from '@/api/index.js'
	export default {
		data() {
			return {
				id:'',
				info:{},
			}
		},
		onLoad(e) {
			this.id = e.id
			// this.info = JSON.parse(e.info)
			// this.info.count = this.info.remainCount
			// this.getInfo()
			this.goodsSaledoGongxuUserId()
		},
		methods: {
			goodsSaledoGongxuUserId() {
				index.goodsSaledoGongxuUserId({id:this.id}).then(res=>{
					this.info = res.data
				})
			},
			jianting() {
				var pages = getCurrentPages();
				console.log(pages.length);
				var Page = pages[pages.length-1];//当前页
				console.log(pages[pages.length-1].route);//输出当前路由
				var prevPage = pages[pages.length-2];
				console.log(pages[pages.length-2].route);//输出上一个页面的路由
				if(pages[pages.length-2].route == 'pagesA/orderAdmin/productiveTask/index'){  //确定要返回到相应页面，在触发
				    prevPage.$vm.reload()
				}
			},
			onKeyInput (event) {
				if(this.info.type == 0) {
					this.info.count = event.target.value
					this.info.allMoney = event.target.value*this.info.money
				} else {
					this.info.count = event.target.value
				}
				
			},
			onKeysInput(event) {
				if(this.info.type == 1) {
					this.info.hour = event.target.value
					this.info.allMoney = event.target.value*this.info.money
				}
				
			},
			getInfo() {
				goodsSaledoGongxuUserMoneyInfo(this.id).then(res=>{
					console.log('成功了吗')
				})
			},
			addBnt(e) {
				// if(this.info.count > this.info.remainCount) {
				// 	return this.$modal.msgError("报工数量不能大于待完成数量！")
				// }
				uni.showModal({
					title: '提示',
					content: '确定报工吗？',
					success :(res)=> {
						if (res.confirm) {
							var data = {
								parentId: this.info.id,
								allMoney: this.info.allMoney,
								money: this.info.money,
								count: this.info.count
							}
							index.addBaogong(data).then(res=>{
								setTimeout(res=>{
									uni.navigateBack(-1)
									this.jianting()
								},100)
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
		}

	}
</script>

<style lang="scss">
	.content {
		padding-left: 20rpx;
		padding-right: 20rpx;
		.form {
			margin-top: 20rpx;
			padding: 20rpx;
			background-color: #ffffff;
			border-radius: 10rpx;
			.titel {
				padding-top: 30rpx;
				padding-bottom: 30rpx;
				color: #333;
				font-size: 28rpx;
				font-weight: bold;
			}
			.itembox {
				border-top: 1px solid #EDEDED;
				display: flex;
				align-items: center;
				padding-top: 30rpx;
				padding-bottom: 30rpx;
				.name {
					text-align: right;
					width: 160rpx;
					color: #999;
					font-size: 28rpx;
				}
				.inputBox {
					padding-left: 20rpx;
					width: 600rpx;
					color: #333;
					font-size: 28rpx;
				}
			}
		}
		.bottom-box {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 750rpx;
			padding: 30rpx;
			padding-bottom: 120rpx;
			height: 120rpx;
			background: #ffffff;
			display: flex;
			justify-content: center;
			.bnt {
				color: #ffffff;
				width: 306rpx;
				height: 88rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				border-radius: 10rpx;
				background: #4D8987;
			}
		}
	}
</style>